#include<bits/stdc++.h>
#define int long long
#define N 5005
using namespace std;
int n,k;
int w[N],a[N],id[N];
int c[N][N],f[N],h[N],e[N],p[N];
int z[N];
int dep[N],vis[N];
int v[N][N],siz[N];
int ans;
const int mod=1e9+7;
vector<int> g[N];
void dfs(int x,int fa){
    dep[x]=dep[fa]+1;
    for(int i:g[x]){
        if(i==fa) continue;
        dfs(i,x);
    }
}
bool cmp(int x,int y){
    return dep[x]>dep[y];
}
void DFS(int x){
    vis[x]=1;
    siz[x]=1;
    for(int i:g[x]){
        if(vis[i]) continue;
        DFS(i);
        siz[x]+=siz[i];
    }
}
signed main(){
    freopen("water.in","r",stdin);
    freopen("water.out","w",stdout);
    scanf("%lld %lld",&n,&k);
    for(int i=1;i<=k;i++) scanf("%lld",&w[i]);
    for(int i=1,l,x;i<=n;i++){
        scanf("%lld",&l);
        for(int j=1;j<=l;j++){
            scanf("%lld",&x);
            x--;
            a[i]|=(1<<x);
        }
    }
    for(int i=1,u,v;i<n;i++){
        scanf("%lld %lld",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++) id[i]=i;
    sort(id+1,id+n+1,cmp);
    h[0]=1;
    for(int i=1;i<=n;i++) h[i]=h[i-1]*2%mod;
    for(int i=0;i<=n;i++) h[i]=(h[i]-1+mod)%mod;
    for(int i=0;i<=n;i++){
        c[i][0]=1;
        for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
    }
    e[0]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++) e[i]=(e[i]+e[i-j]*c[i-1][j-1]%mod)%mod;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++) (p[i]+=c[i][j]*e[n-j]%mod)%=mod;
    for(int i=1;i<(1<<k);i++)
        for(int j=0;j<k;j++) z[i]+=(i>>j&1);
    for(int i=0;i<(1<<k);i++){
        for(int j=1;j<=n;j++) vis[j]=(a[j]&i);
        for(int j=1;j<=n;j++) if(!vis[j]) DFS(j),(f[i]+=p[siz[j]])%=mod;
    }
    for(int i=0;i<(1<<k);i++){
        int y=0;
        for(int j=0;j<(1<<k);j++){
            if((i|j)==j){
                if(z[i^j]&1) y=(y-f[j]+mod)%mod;
                else y=(y+f[j])%mod;
            }
        }
        ans=(ans+w[k-z[i]]*y%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}